<?php
/*
* @Descripttion: 上传
* @Author: jiosen <4631458@qq.com>
* @Date: 2024-06-25 11:05:17
*/
namespace app\controller;

use app\BaseController;
use app\service\Upload as ServiceUpload;

class Upload extends BaseController
{
    public function index()
    {
        $file = $this->request->file('file');
        $type = $this->request->param('type','','trim');

        if(empty($file)){
            return $this->error('请选择文件');
        }

        $re = (new ServiceUpload())->type($type)->save($file);

        if($re['state']){
            return $this->success('上传成功',['url'=> $this->request->domain() . '/' .  str_replace('\\','/',$re['filename'])]);
        }else{
            return $this->error($re['msg']);
        }
    }
}
